package com.framework.validated.pojo;

import com.framework.validated.annotation.Gender;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.Data;

import java.util.List;

@Data
public class User {

    @NotBlank(message = "姓名不能为Null")
    private String name;

    @NotNull(message = "年龄不能为Null")
    @Min(value = 1, message = "年龄最小值不能小于1")
    @Max(value = 150, message = "年龄最大值不能超过150岁")
    private Integer age;

    @Email(message = "邮箱格式不正确！")
    private String email;

    @Size(min = 6, max = 14, message = "密码长度应在6-14位之间")
    private String password;

    @AssertTrue(message = "必须同意使用协议！")
    private Boolean active;

    @Size(min = 1, message = "必须赋予用户一个角色信息！")
    // 若想校验UserRole中的属性，则需要在List中使用注解@Valid注解。
    private List<@Valid UserRole> userRoles;

    @Gender(message = "格式不正确，性别只能是男或女！")
    private String gender;

}
